﻿using System;
using System.Collections.Generic;
using System.Xml;
using System.IO;

namespace VidoopSecure
{
    public class VoicePtl
    {
        /// <summary>
        /// A One Key Login (No PIN) identifier.
        /// </summary>
        public string Id
        {
            get { return _id; }
            set { _id = value; }
        }

        /// <summary>
        /// Phone number to which the call will be made.
        /// </summary>
        public string Phone
        {
            get { return _phone; }
            set { _phone = value; }
        }

        /// <summary>
        /// Status of the call being made.
        /// </summary>
        public string SendStatus 
        {
            get { return _sendStatus; }
            set { _sendStatus = value; }
        }

        /// <summary>
        /// Status of the authentication being made in the call.
        /// </summary>
        public string AuthenticationStatus 
        {
            get { return _authenticationStatus; }
            set { _authenticationStatus = value; }
        }

        /// <summary>
        /// Generation of a <see cref="VidoopSecure.VoicePtl" /> from
        /// <paramref name="xml"/>.
        /// </summary>
        /// <param name="xml">The XML representation of a 
        /// <see cref="VidoopSecure.VoicePtl" />. </param>
        /// <returns>An instance of <see cref="VidoopSecure.VoicePtl" />.</returns>
        static public VoicePtl FromXml(string xml)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            return GenerateVoicePtlFromXmlDocument(doc);
        }

        /// <summary>
        /// Generation of a <see cref="VidoopSecure.VoicePtl" /> from
        /// <paramref name="stream"/>.
        /// </summary>
        /// <param name="stream">A <see cref="System.IO.Stream" /> 
        /// representing the XML of a <see cref="VidoopSecure.VoicePtl" />.
        /// </param>
        /// <returns>An instance of <see cref="VidoopSecure.VoicePtl" />.</returns>
        static public VoicePtl FromXml(Stream stream)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(stream);
            return GenerateVoicePtlFromXmlDocument(doc);
        }

        static private VoicePtl GenerateVoicePtlFromXmlDocument(XmlDocument doc)
        {
            VoicePtl voicePtl = new VoicePtl();

            voicePtl.Id = doc.GetElementsByTagName("id")[0].InnerText;
            voicePtl.Phone = doc.GetElementsByTagName("phone")[0].InnerText;
            voicePtl.SendStatus = doc.GetElementsByTagName(
                "send_status")[0].InnerText;
            voicePtl.AuthenticationStatus = doc.GetElementsByTagName(
                "authentication_status")[0].InnerText;

            return voicePtl;
        }

        private string _id;
        private string _phone;
        private string _sendStatus;
        private string _authenticationStatus;
    }
}
